from pathlib import Path

path = Path("programming.txt")
# write_text() 方法接受单个实参，即要写入文件的字符串。
path.write_text("I love programming.\n")